#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
#include <utility>
using namespace std;

#define ALL(v) (v).begin(), (v).end()
#define LET(x,a) typeof(a) x(a)
#define FOR(i,a,n) for(LET(i,a);i!=n;i++)
#define REP(i,n) FOR(i,0,n)
#define sz size()
#define pb push_back
#define LL long long
#define VI vector<int>
#define VII vector< VI >
#define VS vector<string>
#define PRINT(x) REP(i,x.sz) cout<<x[i]<<endl;
#define GI ({int a; cin>>a; a;})
#define COUNT(f,x) ({int _=0;f _+=(x);_;})
#define MIN(f,x) ({LL _=LINF;f _<?=(x);_;})
#define MAX(f,x) (-MIN(f,-(x)))

class SetMetric {
public:
	int nearness(vector <int>, vector <int>);
};

int SetMetric::nearness(vector <int> tar, vector <int> cand) {
	int ans = 0;
	sort(ALL(tar)); sort(ALL(cand));
	while(tar.sz){
		int min = 1 << 30; vector<int>::iterator it;
		FOR(i,cand.begin(),cand.end()){ 
			if( abs( *i - *(tar.begin()) ) < min ) { it = i; min = abs(*i-*(tar.begin())); }
		}
		cand.erase(it); tar.erase(tar.begin());
		ans += min;
	}
	
	return ans;
}


double test0() {
	int t0[] = {4,9,2,1};
	vector <int> p0(t0, t0+sizeof(t0)/sizeof(int));
	int t1[] = {9,1,2,3,5,6};
	vector <int> p1(t1, t1+sizeof(t1)/sizeof(int));
	SetMetric * obj = new SetMetric();
	clock_t start = clock();
	int my_answer = obj->nearness(p0, p1);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p2 = 1;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p2 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p2 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test1() {
	int t0[] = {0};
	vector <int> p0(t0, t0+sizeof(t0)/sizeof(int));
	int t1[] = {1000,-1000,0};
	vector <int> p1(t1, t1+sizeof(t1)/sizeof(int));
	SetMetric * obj = new SetMetric();
	clock_t start = clock();
	int my_answer = obj->nearness(p0, p1);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p2 = 0;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p2 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p2 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test2() {
	int t0[] = {1000,-1000,0,5,289,-40};
	vector <int> p0(t0, t0+sizeof(t0)/sizeof(int));
	int t1[] = {30,821,-777,-52,91,444,-134,85};
	vector <int> p1(t1, t1+sizeof(t1)/sizeof(int));
	SetMetric * obj = new SetMetric();
	clock_t start = clock();
	int my_answer = obj->nearness(p0, p1);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p2 = 679;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p2 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p2 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}

int main() {
	int time;
	bool errors = false;
	
	time = test0();
	if (time < 0)
		errors = true;
	
	time = test1();
	if (time < 0)
		errors = true;
	
	time = test2();
	if (time < 0)
		errors = true;
	
	if (!errors)
		cout <<"You're a stud (at least on the example cases)!" <<endl;
	else
		cout <<"Some of the test cases had errors." <<endl;
}

//Powered by [KawigiEdit] 2.0!
